package com.example.animproperty;

import androidx.appcompat.app.AppCompatActivity;

import androidx.appcompat.app.AppCompatActivity;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ValueAnimator valueAnimator = ValueAnimator.ofFloat(0f, 1f);
        valueAnimator.setDuration(5000);
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float value = (float) animation.getAnimatedValue();
                Log.e("leo", "onAnimationUpdate: " + value);
            }
        });
        valueAnimator.start();

        //设置循环旋转图片
        ImageView img = findViewById(R.id.iv);
        ObjectAnimator objectAnimator2 = ObjectAnimator.ofFloat(img, "rotation", 0, 359);
        objectAnimator2.setRepeatCount(ValueAnimator.INFINITE);  //负数表示无限次
        objectAnimator2.setDuration(2000);
        objectAnimator2.setInterpolator(new LinearInterpolator());
        objectAnimator2.start();

        //第二种设置循环旋转图片
       /* RotateAnimation animation = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        animation.setFillAfter(true);
        animation.setRepeatCount(Animation.INFINITE);
        animation.setDuration(1000);
        animation.setInterpolator(new LinearInterpolator());
        img.setAnimation(animation);
        animation.start();*/
        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //animation.cancel();
                objectAnimator2.cancel();
            }
        });



        TextView textView = findViewById(R.id.tv);
        ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(textView,
                "alpha",0f,1f);  //淡入淡出动画 0-1显示完
        objectAnimator.setDuration(14000);  //动画持续时间
        objectAnimator.start();

        objectAnimator.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {//动画开始的时候调用

            }

            @Override
            public void onAnimationEnd(Animator animation) {//动画结束的时候调用

            }

            @Override
            public void onAnimationCancel(Animator animation) {//动画取消时调用

            }

            @Override
            public void onAnimationRepeat(Animator animation) { //动画重复执行时被调用

            }
        });

        objectAnimator.addListener(new AnimatorListenerAdapter() { //自定义
            @Override
            public void onAnimationStart(Animator animation) {

                super.onAnimationStart(animation);
            }
        });





    }
}